<?php
/*  
  Copyright (c) 2010-02 SongCMS 
  SongCMS All Rights Reserved. 
  Support:www.SongCMS.com
  QQ:544255858   19951025
  Author:Song  Version:3.17
  Date:2010-08-12 09:28:32
*/

include_once('Admin.php');
if (!is_numeric($_GET['ID'])) {MsgBox (1,'ID参数出现非数字错误！','-1');}

if ($_POST['Action']=='UpDate'){
	$JurisdiCtion = $_POST['JurisdiCtion']; //接收并转换复选项为数组
	if ($JurisdiCtion != '') {$JurisdiCtion = implode(",",$JurisdiCtion);}
	$Count = $db->SelectSQL("SELECT COUNT(`ID`) FROM `" . $dbprefix . "admin` WHERE `ID` != " . $_GET['ID'] . " && `UserName` = '" . $_POST['UserName'] . "'");
	$Count = $Count[0][0];
	if ($Count != 0){AdminLog(1,1,'修改管理员(被修改的管理员ID号：' . $_GET['ID'] . ')失败，原因：已经存在的用户名！'); MsgBox (1,'该用户名已经存在！','-1');}
	//检测是否对当前用户进行降级操作(为保证系统中至少有一位超级管理员，禁止对当前已登录的超级管进员进行权限降低修改)
	if ($_SESSION['ID']==$_GET['ID'] && $_POST['levels']!=1){AdminLog(1,1,'尝试对当前已登录管理员进行权限级别降级修改，结果：操作失败！'); MsgBox (1,'操作失败，该管理员已经登录，无法对其进行降低权限级别操作！','1');}
	//检测是否对密码进行了修改
	$PRmm = $db->SelectSQL("SELECT `PassWord` FROM `" . $dbprefix . "admin` WHERE `ID` = " . $_GET['ID']);
	$PRmm[0][0] == $_POST['PassWord'] ? $PassWord = $_POST['PassWord'] : $PassWord = md5($_POST['PassWord']);

	$SQL = "UPDATE `" . $dbprefix . "admin` SET `UserName` = '" . $_POST['UserName'] . "',`PassWord` = '" . $PassWord . "',`JurisdiCtion` = '" . $JurisdiCtion . "',`Levels` = '" . $_POST['levels'] . "' WHERE `ID` = " . $_GET['ID'];
	unset($Rs,$PRmm,$PassWord,$JurisdiCtion);
	if($db->ExecuteSQL($SQL)){
		AdminLog(1,1,'修改管理员(ID号：' . $_GET['ID'] . ')资料，结果：操作成功！');
		MsgBox (1,'管理员修改成功！','AdminManage.php');
	} else {
		AdminLog(1,1,'修改管理员(ID号：' . $_GET['ID'] . ')资料，结果：操作失败！');
		MsgBox (1,'管理员修改失败！','1');
	}
}

$Rs = $db->SelectSQL("SELECT `ID`,`UserName`,`PassWord`,`JurisdiCtion`,`Levels` FROM `" . $dbprefix . "admin` WHERE `ID` = " . $_GET['ID']);
if (count($Rs) == 0) {MsgBox(1,'不存在的管理员！','-1');}
$JurisdiCtion = explode(',',$Rs[0][3]);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="./images/adminstyle.css" rel="stylesheet" type="text/css" />
<link rel="Shortcut Icon" href="../favicon.ico">
<link rel="Bookmark" href="../favicon.ico">
<script src="../js/csshovernotie6.js" type="text/javascript"></script>
<script type="text/javascript"> 
var flag = true;
function selall(obname){
  	var e = document.getElementsByName(obname);
	for (var i=0;i<e.length;i++){
     	e[i].checked  = flag;
   	}
	flag = !flag;
} 
function check(State){
	if (State == 0) {
		document.getElementById("Super").style.display = "block";
	} else {
		document.getElementById("Super").style.display = "none";
	}
}
function nCheck() {
	if(document.form1.UserName.value.length<5){
		alert('用户名不得少于5个字符。') ;
		document.form1.UserName.focus();
		return false;		
	}
	if(document.form1.PassWord.value.length<5){
		alert('用户密码不得少于5个字符。') ;
		document.form1.PassWord.focus();
		return false;		
	}
	if(document.form1.PassWord.value != document.form1.PassWord2.value){
		alert('两次输入的密码不一致。') ;
		document.form1.PassWord2.focus();
		return false;		
	}
}
</script> 
</head>
<body>
<br />
<table width="98%" border="0" align="center" cellpadding="4" cellspacing="1">
	<tr><td align="right">		
		<input type="button" value="添加管理员" onClick="javascript:location.href='AdminAdd.php?Lang=<?php echo $Lang?>'">
		<input type="button" value="管理员管理" onClick="javascript:location.href='AdminManage.php?Lang=<?php echo $Lang?>'">	
	</td></tr>
</table>
<table width="98%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
  <form id="form1" name="form1" method="post" action="AdminUpDate.php?ID=<?php echo $_GET['ID']?>" onSubmit="return nCheck()">
  <tr class="odd">
    <td colspan="3" align="center" class="Main_Title">修改后台管理员</td>
  </tr>
  <tr class="odd">
    <td align="right">权限级别：</td>
    <td>
    <input name="levels" type="radio" value="0" onClick="return check(0)" <?php if ($Rs[0][4]==0){echo 'checked';}?> />普通管理员
    <input name="levels" type="radio" value="1" onClick="return check(1)" <?php if ($Rs[0][4]==1){echo 'checked';}?> />超级管理员
    </td>
    <td>普通管理员：无权对其他管理员进行管理，管理权限可单独设定；</td>
  </tr>
  <tr class="odd">
    <td align="right">用 户 名：</td>
    <td><input name="UserName" type="text" class="input2" id="UserName" value="<?php echo $Rs[0][1]?>" maxlength="20" />
      <span class="red">*</span></td>
    <td>5-20个字符组成</td>
  </tr>
  <tr class="odd">
    <td align="right">密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码：</td>
    <td><input name="PassWord" type="password" class="input2" id="PassWord" value="<?php echo $Rs[0][2]?>" maxlength="32" onClick="this.value='';" onMouseOver="this.select();"  />
      <span class="red">*</span></td>
    <td>5-20个字符组成</td>
  </tr>
  <tr class="odd">
    <td align="right">确认密码：</td>
    <td><input name="PassWord2" type="password" class="input2" id="PassWord2" value="<?php echo $Rs[0][2]?>" maxlength="32" onClick="this.value='';" onMouseOver="this.select();"  />
      <span class="red">*</span></td>
    <td>5-20个字符组成</td>
  </tr>
  <tr id="Super" class="odd" <?php if ($Rs[0][4]==1){echo 'style="display:none;"';}?>>
    <td align="right">管理权限：</td>
<td>
<input name="chkAll" type="checkbox" id="chkAll" onClick="selall('JurisdiCtion[]')" value="checkbox"><font color="#0000FF">全部选中/全部取消</font><br />
<?php
$n = 0;
foreach ($xSystem as $x => $m){
	if($m[0] == 1 && $m[6] == 1){
		$AdminPage[] = $m;
	}
}
echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">' . "\n";
echo '<tr>' . "\n";
foreach ($AdminPage as $i => $p){
	echo '<td>';
	if ($p[2] != 'AdminAdd.php' && $p[2] != 'AdminManage.php'){ //管理员管理(前两项)设为只读，禁止对管理员管理进行选择
		$checked = in_array($p[2],$JurisdiCtion) ? ' checked="checked"' : '';
		echo '<input name="JurisdiCtion[]" type="checkbox" id="JurisdiCtion[]" value="' . $p[2] . '"' . $checked . ' />' . $p[3] . "\n";
	} else {
		echo '<input disabled type="checkbox" />' . $p[3] . "\n";
	}
	echo '</td>';
	if((($n++)+1)%3==0){echo '</tr><tr>';}
}
echo '</tr></table>' . "\n";
?>
</td>
    <td>该项只对普通管理员有效，超级管理员没有限制；</td>
  </tr>
  <tr class="odd">
    <td><input name="Action" type="hidden" id="Action" value="UpDate" /></td>
    <td><input type="submit" name="button" id="button" value="提 交" class="submit" />
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="reset" name="button2" id="button2" value="重 置" class="submit" /></td>
    <td>&nbsp;</td>
  </tr>
</form>
</table>
</body>
</html>